<template>
  <div style="overflow: hidden; padding-bottom: 80px">
    <div class="boxs-right" ref="boxsRight">
      <titles :title="props.info.text" style="margin-bottom: 32px; justify-content: left" />
      <textMax :data="props.info.remarks" :maxLen="120" />
    </div>
    <div class="boxs-item">
      <div
        @mouseenter="addWidth"
        @mouseleave="subWidth"
        ref="boxsLeft"
        @click="pathChild(props.info, 0)"
        class="boxs-left1"
        style="margin-right: 20px; cursor: pointer"
      >
        <img
          class="item-left"
          :src="urls + props.info.children[0].value + `?imageView2/1/h/380/format/webp`"
          alt=""
          v-if="props.info.children[0].value"
        />
        <UnitImageNull v-else></UnitImageNull>

        <div class="shadow"></div>
        <div class="remarks" style="cursor: pointer">
          <p class="titleText" @click="pathChild(props.info)" :style="{ fontSize: store.styleInfo.mintitleSize }">
            {{ props.info.children[0].text }}
          </p>
          <p
            class="remarksText"
            @click="pathChild(props.info, 0)"
            :style="{
              fontSize: store.styleInfo.contentSize,
              fontFamily: store.styleInfo.textFamily,
            }"
          >
            {{ props.info.children[0].remarks }}
          </p>
        </div>
      </div>
      <div
        @mouseenter="addWidth1"
        @mouseleave="subWidth1"
        ref="boxsLeft1"
        class="boxs-left"
        @click="pathChild(props.info, 1)"
        style="cursor: pointer"
      >
        <img
          class="item-left"
          :src="urls + props.info.children[1].value + '?imageView2/1/h/380/format/webp'"
          alt=""
          v-if="props.info.children[1].value"
        />
        <UnitImageNull v-else></UnitImageNull>
        <!-- <img class="item-left" src="http://101.34.143.36:8890/api/image/387939155165253/h_380,w_580" alt="" v-else /> -->
        <div class="shadow"></div>
        <div class="remarks" style="cursor: pointer">
          <p class="titleText" @click="pathChild(props.info, 1)" :style="{ fontSize: store.styleInfo.mintitleSize }">
            {{ props.info.children[1].text }}
          </p>
          <p
            class="remarksText"
            @click="pathChild(props.info, 1)"
            :style="{
              fontSize: store.styleInfo.contentSize,
              fontFamily: store.styleInfo.textFamily,
            }"
          >
            {{ props.info.children[1].remarks }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import textMax from './component/textMax2.vue';
import { onMounted, ref } from 'vue';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const router = useRouter();
const route = useRoute();
const store = useProjectStore();
const boxsRight = ref(null);
const boxsLeft = ref(null);
const boxsLeft1 = ref(null);
const props = defineProps({
  info: {
    type: Object,
  },
});
const pathChild = (e: any, index: number) => {
  store.setchildModel(e);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { current: index },
  });
};
onMounted(() => {
  console.log(boxsLeft.value);
  animation();
});
const animation = () => {
  let canTrigger = true; // 标记是否可以触发

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码s
        console.log('c', boxsLeft.value);
        boxsRight.value.classList.add('animation-box6');
        boxsLeft.value.classList.add('animation-box2');
        boxsLeft1.value.classList.add('animation-box3');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        if (boxsRight.value) {
          boxsRight.value.classList.remove('animation-box6');
          boxsLeft.value.classList.remove('animation-box2');
          boxsLeft1.value.classList.remove('animation-box3');
        }
      }
    });
  });
  observer.observe(boxsRight.value);
};
// const imgwidth = ref(580)
const addWidth = () => {
  // imgwidth.value = 780
  boxsLeft.value.style.width = '780px';
  boxsLeft1.value.style.width = '380px';
};
const subWidth = () => {
  boxsLeft.value.style.width = '580px';
  boxsLeft1.value.style.width = '580px';
};
const addWidth1 = () => {
  boxsLeft1.value.style.width = '780px';
  boxsLeft.value.style.width = '380px';
};
const subWidth1 = () => {
  boxsLeft.value.style.width = '580px';
  boxsLeft1.value.style.width = '580px';
};
</script>

<style lang="less" scoped>
@import './index.less';

.boxs-right {
  width: 900px;
  min-height: 143px;

  :deep(.tj) {
    line-height: 32px !important;
  }
}

.boxs-item {
  width: 100%;
  display: flex;
  // justify-content: space-between;
  margin-top: 50px;
  transition: all 0.5s;
  // flex: 1;
}

.boxs-left1,
.boxs-left {
  width: 580px;
  height: 380px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.5s;
  flex-shrink: 1 // flex: 1;
    // width: 48%;/
    // display: flex;
    // justify-content: space-between;
}

.item-left {
  width: 48%;
  width: 100%;
  height: 380px;
  // transition: all 0.5s;
}

.remarks {
  width: 80%;

  position: absolute;
  top: 111px;
  left: 10%;
  z-index: 101;
  text-align: center;
  color: #fff;
  opacity: 0;
  transition: all 0.5s;

  .titleText {
    font-size: 20px !important;
    margin-bottom: 32px;
    font-family: SourceHanSerifCN-Bold
  }

  .remarksText {
    width: 640px;
    line-height: 30px;
    text-align: left;
 overflow: hidden; //溢出内容隐藏
    text-overflow: ellipsis; //文本溢出部分用省略号表示
    display: -webkit-box; //特别显示模式
    -webkit-line-clamp: 3; //行数
    line-clamp: 3;
    -webkit-box-orient: vertical; //盒子中内容竖直排列
  }
}

.shadow {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}

.boxs-left,
.boxs-left1 {
  transition: all 0.5s;
}

.boxs-left:hover,
.boxs-left1:hover {
  transform: scale(1.1);
}

.boxs-left:hover .shadow,
.boxs-left1:hover .shadow {
  background: rgba(0, 0, 0, 0.4);
}

.boxs-left:hover .remarks,
.boxs-left1:hover .remarks {
  opacity: 1;
}
</style>
